﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseAccessLayer;

namespace WebApplication
{
    public partial class Offers_Posted_Results : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Master.FindControl("RightAdvertisement").Visible = false;
            if (!IsPostBack)
            {
                fillGrid();
            }
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divbreadcrum")).InnerHtml = @"<a href='default.aspx'>Home</a> >  <a href='menu.aspx'>Menu</a> > <a href='real_estate_search.aspx'>Real Estate Search</a> >  <a href='Real_Estate_Search_Menu.aspx'>Real Estate Search Menu</a> > <a href='javascript:void();' onclick='history.go(-1);'>Offers Posted</a> > <span>Offers Posted Results</span> ";
            h3Header.InnerHtml = string.Concat(Request["co"], " - ", Request["s"], " - ", Request["c"]=="City"?"All City":Request["c"], "- Real Estate Offers Posted"); 
        }

        protected void fillGrid()
        {
            string country = Request["co"];
            string city = Request["c"] == "City" ? "All City" : Request["c"];
            string Prop = Request["P"];
            string PropType = Request["PT"];
            lblProperty.Text = Prop;
            if (Prop == "All")
            {
                divAll.Style["display"] = "block";
                divCheckAll.Style["display"] = "none";
                lblProperty.Text = "";
            }
            else
            {
                divAll.Style["display"] = "none";
                divCheckAll.Style["display"] = "block";
               
            }
            List<PostOfferSt> lst = PostOffer.SearchResult(country, city, Prop, PropType);
            if (Request.QueryString["Mode"] != null && Request.QueryString["Mode"].ToString() != "")
            {
                if (Request.QueryString["Mode"].ToString() == "Buy")
                {
                    lst = (from g in lst where g.PriceMode == "Sale" select g).ToList();
                }
                else if (Request.QueryString["Mode"].ToString() == "Rent")
                {
                    lst = (from g in lst where g.PriceMode == "Lease" select g).ToList();
                }
                else
                {
                    lst = (from g in lst where g.PriceMode == "Sale" || g.PriceMode == "Lease" || g.PriceMode == "Investiment" select g).ToList();
                }
            }
            if (lst!=null)
            {
                gvResidentail.DataSource = lst;
                gvResidentail.DataBind();
                grd_Comercial.DataSource = lst; grd_Comercial.DataBind();
                grd_Residential.DataSource = lst; grd_Residential.DataBind();
                dvresult.Visible = true;
            }
            else
            {
                gvResidentail.EmptyDataText = "No Result found";
                //dvresult.Visible = false;
            }
            

        }
        protected void gvResidentail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // Display the company name in italics.
                if (Session["IsMember"] == null || Session["IsMember"].ToString() != "True")
                {
                    ((Label)e.Row.Cells[8].FindControl("lblConactName")).Text = "Savory Housing";
                    ((Label)e.Row.Cells[8].FindControl("lblLandLineNo")).Text = "00966507040123";
                    ((Label)e.Row.Cells[9].FindControl("lblContactNo2")).Text = "TBD";
                }
            }

        }
    }
}